<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="java.sql.Date"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="startup.model.trip.MissionRequest"%>
<%@page import="startup.model.trip.PaymentMethod"%>
<%@page import="startup.model.trip.Reimbursement"%>
<%@page import="startup.model.user.Student"%>
<%@page import="startup.utils.DateTool"%>
<%
	try
	{
		Student student = ( Student )session.getAttribute( "currentSessionUser" );

		try
		{
			MissionRequest reimburesementContainer = ( MissionRequest )session.getAttribute( "missionRequest" );
			reimburesementContainer.setReimbursement();
			Reimbursement toSubmit = reimburesementContainer.getReimbursement();

			toSubmit.setExpensesSustainedBefore( Float.parseFloat( request.getParameter( "expenses" ) ) );
			toSubmit.setDestination( request.getParameter( "actual_destination" ) );
			toSubmit.setBeginningDateAndTime( new Timestamp( DateTool.getDateInMillis( request.getParameter( "actual_begin_date_time" ) ) ) );
			toSubmit.setEndingDateAndTime( new Timestamp( DateTool.getDateInMillis( request.getParameter( "actual_end_date_time" ) ) ) );
			toSubmit.setAccomodationExpensesAttachment( Integer.parseInt( request.getParameter( "num_lodging_receipts" ) ) );
			toSubmit.setAccomodationDays( Integer.parseInt( request.getParameter( "number_of_nights" ) ) );
			toSubmit.setRegistrationFee( Float.parseFloat( request.getParameter( "registration_fee" ) ) );
			toSubmit.setTotalLodgingExpenses( Float.parseFloat( request.getParameter( "total_lodging_expenses" ) ) );
			toSubmit.setMealsExpensesAttachment( Integer.parseInt( request.getParameter( "num_meals_invoices" ) ) );
			toSubmit.setMealsDays( Integer.parseInt( request.getParameter( "num_days_of_meals" ) ) );
			toSubmit.setTotalMealExpenses( Float.parseFloat( request.getParameter( "total_meal_expenses" ) ) );
			toSubmit.setTravelExpenses( "Departure from " +
										request.getParameter( "fromDeparture" ) +
										" to " + request.getParameter( "toDeparture" ) +
										" at " + request.getParameter( "dateDeparture" ) +
										"; Return from " +
										request.getParameter( "fromReturn" ) +
										" to " + request.getParameter( "toReturn" ) +
										" at " + request.getParameter( "dateReturn" ) );
			toSubmit.setDepartureBorderCrossDatetime( new Timestamp( DateTool.getDateInMillis( request.getParameter( "departure_border_cross_datetime" ) ) ) );
			toSubmit.setArrivalBorderCrossDatetime( new Timestamp( DateTool.getDateInMillis( request.getParameter( "arrival_border_cross_datetime" ) ) ) );
			toSubmit.setHighwayTollFees( Float.parseFloat( request.getParameter( "highway_toll_fees" ) ) );
			toSubmit.setPersonalVeicleKmToAirport( Integer.parseInt( request.getParameter( "personal_veichle_KM_travelled" ) ) );
			toSubmit.setPersonalVeicleColleguesNames( request.getParameter( "personal_veichle_colleagues" ) );
			toSubmit.setTotalTransportExpenses( Float.parseFloat( request.getParameter( "total_transport_expenses" ) ) );
			toSubmit.setSelfDeclarationMissingRecepits( request.getParameter( "self_declaration_missing_recepits" ) );
			toSubmit.setOtherCostsDescription( request.getParameter( "other_costs_description" ) );
			toSubmit.setOtherCostsAmount( Float.parseFloat( request.getParameter( "other_costs_amount" ) ) );
			toSubmit.setRequestedPaymentMethod( PaymentMethod.valueOf( request.getParameter( "paymentMethod" ) ) );
			if( reimburesementContainer.getArePersonalFundsUsed().booleanValue() )
			{
				toSubmit.setPersonalFundsAmount( Integer.parseInt( request.getParameter( "personalFundsUsed" ) ) );
				if( toSubmit.getPersonalFundsAmount() >
					( ( Student )session.getAttribute( "currentSessionUser" ) ).getPersonalFunds() )
				{
					throw new RuntimeException( "Check your personal funds! Your funds cannot cover this amount!" );
				}
			}
			if( reimburesementContainer.getFirstAlternativeFundManagerId() != null && reimburesementContainer.getFirstAlternativeFundManagerId() > 0 )
			{
				toSubmit.setFirstAlternativeFundAmount( Integer.parseInt( request.getParameter( "firstFundAmount" ) ) );
			}
			if( reimburesementContainer.getSecondAlternativeFundManagerId() != null && reimburesementContainer.getSecondAlternativeFundManagerId() > 0 )
			{
				toSubmit.setSecondAlternativeFundAmount( Integer.parseInt( request.getParameter( "secondFundAmount" ) ) );
			}
			reimburesementContainer.updateOnWorkingDB();

			session.removeAttribute( "missionRequest" );
		}
		catch( RuntimeException runtimeException )
		{
			if( runtimeException.getClass().equals( NullPointerException.class ) )
			{
				runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
															 "try reloading page.<br />" +
															 "If the problem persists, please report it to the administration." );
			}
			request.setAttribute( "exception", runtimeException );
			request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
		}
%>
<!DOCTYPE html>
<html>
	<head>
        <meta charset="windows-1252">
        <title>Request Sent</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <!-- Le styles -->
        <link href="styles/bootstrap.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
    </head>
    <body>
        <!--Barra Superiore-->
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="brand" href="#">Student : <%=student.getSurname()%> <%=student.getName()%> </a>
                    <div class="nav pull-right">
                        <ul class="nav">
                            <li>
                                <form action="Logout" method="post">
                                    <button class="btn btn-primary btn-small">Sign out</button>
                                </form>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <!--CONTENUTO GRANDE -->
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span3" style="position:fixed;">
                    <div class="well sidebar-nav">
                        <ul class="nav nav-list">
                            <li class="nav-header">Location</li>
                            <li><a href="studentChooseHistoryToShow.jsp"><i class="icon-home"></i> Home</a></li>
                            <li><a href="studentActualHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> ACTIVE History</a></li>
                            <li><a href="studentTerminatedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> TERMINATED History</a></li>
                            <li><a href="studentDeletedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> DELETED History</a></li>
                            <li class="nav-header">Function</li>
                            <li><a href="studentNewMissionRequestSubmission.jsp"><i class="icon-pencil"></i> New Mission Request</a></li>
                            <li><a href="studentShowNewAdvanceCompensation.jsp"><i class="icon-pencil"></i> New Advance Compensation</a></li>
                            <li><a href="studentShowNewReimbursement.jsp"><i class="icon-pencil"></i> New Reimbursement</a></li>
                            <li><a href="#"> &nbsp; &bull; <i class="icon-tasks"></i><del> Complete the forms </del></a></li>
                            <li class="active"><a href="#"> &nbsp;&nbsp; &bull; <i class="icon-white icon-ok"></i> Update </a></li>
                            <li class="divider"></li>
                            <li><a href="studentFAQ.jsp"><i class="icon-info-sign"></i> F.A.Q.</a></li>             
                        </ul>
                    </div><!--/.well -->
                </div><!--/span-->
                <div class="span9" style="margin-left: 26%;">
                    <div class="alert alert-success">
                        <h2 class="alert-heading">Update </h2><br />
                        <h3>Success!</h3><br />
                        <p>
                            Mission succesfully modified.
                        </p>
                    </div>
                </div>
            </div>
        </div><!--/.fluid-container-->
        <div class="navbarCC navbar-fixed-bottom">
            <div class="navbarCC-inner">
                <div class="container-fluid">				
                    <a class="brand" href="#">&copy; 2012 Startup</a>					
                </div>
            </div>
        </div>
		<!-- Il javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.js"></script>
	</body>
</html>
<%
	}
	catch( RuntimeException runtimeException )
	{
		if( runtimeException.getClass().equals( NullPointerException.class ) )
		{
			runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
														 "try reloading page.<br />" +
														 "If the problem persists, please report it to the administration." );
		}
		request.setAttribute( "exception", runtimeException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
%>